/**!
 * 创新创业
 * author: wangkai;
 */
var typeall = "";
var jgxxkeywordall = "";
var typeurl = decodeURI(window.location.href.split("=")[1]);
/* if(typeurl){
	searchbytype(typeurl);
} */

(function(win, $) {

    var $classifylist = $('.ewb-classify-list'),
        $classifyNode = $('.ewb-classify-node', $classifylist)
        $current = $('.current', $classifylist);

    // 分类名称悬停和选中，不显示当前左右虚线
    var effect = function(className) {
        className.prev().addClass('ewb-bgnone');
        className.next().addClass('ewb-bgnone');
    }
    //选中
    effect($current);
    // 悬停
    $classifyNode.hover(function() {
        effect($(this));
    }, function() {
        $(this).prev().removeClass('ewb-bgnone');
        $(this).next().removeClass('ewb-bgnone');
        effect($current);
    });
	
	getFwjgList(0,5);
}(this, jQuery));

function searchbyxxkeyword(){
	var jgxxkeyword = $("#jgxxkeyword").val();
	jgxxkeywordall = jgxxkeyword;
	getFwjgList(0,5);
}
function getFwjgList(pageIndex,pageSize){
	userGuid = $.cookie('the_userid');
	var ParasJson = {
		ValidateData:"epointjweb4.0@5qW-ko3fcm4JGcsqAxFci9lzo2c=@MTUwMTgxMDg0OA==",
		paras:{
		   keywords:jgxxkeywordall,
		   pageIndex:pageIndex+1+"",
		   pageSize:pageSize+""
		  }
	};

	$.ajax({
		url:Util.AjaxRUrl+"getGoodsList",
		type:"post",
		data:JSON.stringify(ParasJson),
		contentType: "application/json;charset=utf-8",
		dataType:"json",
		success:function(msg){
			//console.log(msg);
			if(msg.UserArea){
				for(var i=0;i<msg.UserArea.goodsList.length;i++){
					msg.UserArea.goodsList[i].pictureguid = msg.UserArea.goodsList[i].goodsPic.attachGuid;
					if(msg.UserArea.goodsList[i].goodsjs.length>120){
						msg.UserArea.goodsList[i].goodsjs = msg.UserArea.goodsList[i].goodsjs.substring(0,120)+"......";
					}
				}
			}
			renderList(msg.UserArea.goodsList,pageIndex,pageSize);
			renderPager(pageIndex,pageSize,msg.UserArea.totalNum[0].totalNum);
		}
	});
}

			
//渲染数据
function renderList(data,pageindex,pagesize) {
	var M = Mustache;
	if(typeall=="02"){
		$("#jginfolist").html(M.render($("#jginfolist2-tmpl").html(),{ items: data }));
	}else if(typeall=="03"){
		$("#jginfolist").html(M.render($("#jginfolist3-tmpl").html(),{ items: data }));
	}else{
		$("#jginfolist").html(M.render($("#jginfolist-tmpl").html(),{ items: data }));
	}
	$('.ewb-number').each(function(index, el) {
		$(this).text((pageindex*pagesize)+(index+1));
	});
}

//分页
function renderPager(pageindex,pagesize,total) {
	if ($(".pager").pagination()) {
		$(".pager").pagination('destroy');
	}

	$(".pager").pagination({
		pageIndex: pageindex,
		pageSize: pagesize,
		total: total,
		showJump: true,
		jumpBtnText: 'Go'
	});

	$(".pager").on("pageClicked", function(event, data) {
		//分页按钮点击事件
		//console.log(data);
		getFwjgList(data.pageIndex, data.pageSize);
	});

	$(".pager").on("jumpClicked", function(event, data) {
		//跳转按钮点击事件
		getFwjgList(data.pageIndex, data.pageSize);
	});

}
